package com.sykj.manage.web;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
 * 
 * @author 高志远
 *2018年9月10日下午3:13:03
 *类描述：角色表[sys_role控制类
 */
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.manage.service.SysRoleService;
import com.sykj.manage.model.SysRole;
import com.sykj.util.ManageBody;
import com.sykj.util.PageUtil;
@Controller
@RequestMapping("/role")
public class SysRoleConller {
	@Autowired
	SysRoleService sysRoleService;
	
	 
	/**
	 * 页面初始化
	 * 角色查询
	 */
	@RequestMapping("/list")
	@ResponseBody
	public ManageBody index(SysRole sysRole,Model model,Integer offset,Integer pageSize){
		PageHelper.startPage(offset==null?1:PageUtil.getPageNum(offset, pageSize),pageSize==null?10:pageSize,true);
		List<SysRole> sysRoles = sysRoleService.getAll(sysRole);
		PageInfo<SysRole> pageInfo = new PageInfo<SysRole>(sysRoles);
		return ManageBody.getData((int)pageInfo.getTotal(), pageInfo.getList(), "");
	}
	
	/**
	 * 删除角色
	 * @param role_id
	 * @return
	 */
	@RequestMapping("/delRoles")
	@ResponseBody
	public Object delMenus(@RequestParam("role_id")String[] role_id) {
		int cnt = sysRoleService.delRoles(role_id);
		return cnt;
	}
	
	/**
	 * 
	 * @param sysRole
	 * @return
	 * 添加角色
	 */
	@RequestMapping("/addRole")
	@ResponseBody
	public Object addRole(SysRole sysRole) {
		Date date = new Date();
		sysRole.setCreate_time(date);
		int addcnt =sysRoleService.addRole(sysRole);
		return addcnt;
	}
	
	/**
	 * 按role_id查询角色
	 * @param role_id
	 * @return
	 */
	@RequestMapping("/findRoleById")
	@ResponseBody
	public Object findRoleById(@RequestParam("role_id")String role_id) {
		SysRole role = sysRoleService.findRoleById(role_id);
		return role;
	}
	
	/**
	 * 修改角色
	 * @param sysRole
	 * @return
	 */
	@RequestMapping("/updRole")
	@ResponseBody
	public Object updRole(SysRole sysRole) {
		Date date = new Date();
		sysRole.setModify_time(date);
		int updcnt = sysRoleService.updRole(sysRole);
		return updcnt;
	}

}
